package com.central.scheduler.service.quartz;

import com.alibaba.druid.pool.DruidDataSource;
import com.central.scheduler.service.bean.SpringApplicationContext;
import org.quartz.utils.ConnectionProvider;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author Tindy
 * @date 2021/11/15
 * @describe
 * druid connection provider
 */
public class DruidConnectionProvider implements ConnectionProvider {

    private final DruidDataSource dataSource;

    public DruidConnectionProvider(){
        this.dataSource = SpringApplicationContext.getBean(DruidDataSource.class);
    }

    @Override
    public Connection getConnection() throws SQLException {
        return dataSource.getConnection();
    }

    @Override
    public void shutdown() throws SQLException {
        dataSource.close();
    }

    @Override
    public void initialize() throws SQLException {
        //NOP
    }
}

